<template>
    <div id="oplog" class="w-h-100 pos-r flex-1 apply-container" style="box-sizing: border-box;overflow:hidden;">
        <div class="w-h-100 ver-flex pos-a" style="box-sizing: border-box; padding: 6px;">
            <div style="box-sizing: border-box;">
                <el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
                    <el-form class="box-f" ref="queryForm" :inline="true" label-width="auto">
                        <el-form-item :label="$t('wU5NXbjZvkU7jbatOadx')">
                            <el-input style="width:120px;" v-model="searchOne" :placeholder="$t('hrSzpvkfkCi0eeKfmt89k')" clearable  />
                        </el-form-item>
                        <el-form-item :label="$t('uD_9Gn1fvn0Dzyqy65xaZ')">
                            <el-input style="width:120px;" v-model="searchTwo" :placeholder="$t('fFuImBk3xY2E6vHRi1fqo')" clearable  />
                        </el-form-item>
                        <el-form-item :label="$t('a0MgvFpCpbOtPs7oIYcnX')">
                            <el-select style="width:120px;" v-model='searchThree' :placeholder="$t('aYoh21Dz16S6o18X1IfC8')" clearable>
                                <el-option :label="$t('3EkGxudDEyOsInRv3Qt')" :value="0" />
                                <el-option :label="$t('qrSkKBzc_8rFov_4xDMdY')" :value="1" />
                            </el-select>
                        </el-form-item>
                        <el-form-item :label="$t('gLonEtPfn2B5jc_3R7S')">
                            <el-date-picker
                                v-model="searchFour"
								style="width: 240px;"
                                type="daterange"
                                start-placeholder="开始时间"
                                end-placeholder="结束时间"
                                value-format="YYYY-MM-DD"
                            />
                        </el-form-item>
                        <el-form-item style="margin-right: 0">
                            <el-button @click="resetClick" icon="ele-Refresh"> {{ $t('eE3IedvHkKmnppI9FzCa7') }} </el-button>
                            <el-button @click="searchClick" type="primary" icon="ele-Search"> {{ $t('5fM07d4lwWlNvcG51m0ao') }} </el-button>
                            <el-popconfirm
                                confirm-button-text="确认"
                                cancel-button-text="取消"
                                icon="InfoFilled"
                                icon-color="#626AEF"
                                :title="$t('0JiI6ygjUnVwv7onISsC')"
                                @confirm="delClick(getData)"
                            >
                                <template #reference>
                                    <el-button type="danger" icon="ele-Delete"> {{ $t('dseZasLb9jVlm4w3Zog0') }} </el-button>
                                </template>
                            </el-popconfirm>
                        </el-form-item>
                    </el-form>
                </el-card>
            </div>

            <div style="box-sizing: border-box;margin-top: 8px;" class="flex-1 pos-r">
                <div class="pos-a w-h-100" style="box-sizing: border-box;">
                    <el-card class="box-card w-h-100" shadow="hover" style="">
                        <div style="" class="w-h-100 ver-flex">
                            <div class="flex-1 pos-r">
                                <div class="pos-a w-h-100">

                                    <el-table :data="list" class="w-h-100" border style="width: 100%" v-loading="loading">
                                        <el-table-column type="index" :label="$t('mypbV2IeRm6WQyRbsoib')" width="55" align="center" :index="indexMethod" />
                                        <el-table-column prop="reqMethod" :label="$t('ljlOFvSw13Jo2D874goqi')"  align="center" :show-overflow-tooltip="true" />
                                        <el-table-column prop="success" :label="$t('qUuARyu3Kt2hpgq29l3V')"  align="center" :show-overflow-tooltip="true" />
                                        <el-table-column prop="ip" label="IP"  align="center" :show-overflow-tooltip="true" />
                                        <el-table-column prop="url" :label="$t('8WnP270B5CpcU64v5DU8')" align="center" :show-overflow-tooltip="true" />
                                        <el-table-column prop="opTime" :label="$t('aMPs3fmGxBkbfOKd3rB')" align="center" :show-overflow-tooltip="true" />
                                        <el-table-column prop="name" :label="$t('b9OzNDrOu0g8VAsLMm6G')" align="center" :show-overflow-tooltip="true" />
                                        <el-table-column prop="account" :label="$t('ttqcs0A7h7ouIeTnpx48')" align="center" :show-overflow-tooltip="true" />
                                        <el-table-column :label="$t('zKDqLt0KBzwdoJgiQgoj')" align="center" >
                                            <template #default="scope">
                                                <el-button class="icon-e" @click="lookClick(scope.row)" icon="ele-Edit" size="small" text type="primary"> {{ $t('w_53isrfamxoT1wPmmZyS') }} </el-button>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                </div>
                            </div>
                            <div style="height: 30px;margin-top: 20px;" class="hr-flex-start">
								<el-pagination
									v-model:currentPage="pageNo"
									v-model:page-size="pageSize"
									:total="totalRows"
									:page-sizes="[10, 20, 50, 100]"
									small
									background
									@size-change="handleSizeChange"
									@current-change="handleCurrentChange"
									layout="total, sizes, prev, pager, next, jumper"
									class="w-h-100"
								/>
							</div>
                        </div>
                    </el-card>
                </div>
            </div>
        </div>
        <OplogDetail
            :lookInfo="lookInfo"
            :isLookDialog="isLookDialog"
            @cancelLookClick="cancelLookClick"
        />
    </div>
    
</template>
<script lang="ts">
import { defineComponent, ref, onMounted , reactive , toRaw } from 'vue'
import getTableData from '/@/utils/getTableData'
import { sysOpLogPage , sysOpLogDelete } from '/@/api/manage/manage.ts'
import OplogDetail from './component/oplog-detail.vue';
export default defineComponent( {
    name: 'oplog',
    components: {
        OplogDetail
    },
    setup(props){
        const isLookDialog = ref()
        const lookInfo = ref()
        const searchOne = ref()
        const searchTwo = ref()
        const searchThree = ref()
        const searchFour = ref()

        const searchObj = reactive({})
        /*** searchClick 查询按钮 */
        const searchClick = () => {

            if(searchOne.value !== undefined){ Object.assign(searchObj,{name: searchOne.value}) } // 日志名称

            if(searchTwo.value !== undefined){ Object.assign(searchObj,{reqMethod: searchTwo.value}) } // 请求方式

            if(searchThree.value !== undefined){ Object.assign(searchObj,{success: Number(searchThree.value)}) } // 是否成功

            if(searchFour.value !== undefined){ // 操作时间
                Object.assign(searchObj,{searchBeginTime: toRaw(searchFour.value)[0]})
                Object.assign(searchObj,{searchEndTime: toRaw(searchFour.value)[1]})
            }

        }

        /*** resetClick 重置按钮 */
        const resetClick = () => {
            searchOne.value = ''
            searchTwo.value = ''
            searchThree.value = ''
            searchFour.value = ''
            
            Object.assign(searchObj,{name: ''})
            Object.assign(searchObj,{reqMethod: ''})
            Object.assign(searchObj,{success: ''})
            Object.assign(searchObj,{searchBeginTime: ''})
            Object.assign(searchObj,{searchEndTime: ''})
        }

        /*** lookClick 详情按钮 */
        const lookClick = (val:any) => {
            lookInfo.value = toRaw(val)
            isLookDialog.value = true
        }

        /*** delClick 清空按钮 */
        const delClick = async (updateFun: Function) => {
            let res = await sysOpLogDelete()
            if(res.success){
                updateFun()
            }
        }

        /*** cancelLookClick 查看关闭事件 */
        const cancelLookClick = () => {
            isLookDialog.value = false
        }
        onMounted(() => {
            
        })
        return {
            ...getTableData(sysOpLogPage,{},searchObj),
            lookClick,
            isLookDialog,
            cancelLookClick,
            lookInfo,
            delClick,
            searchOne,
            searchTwo,
            searchThree,
            searchFour,
            searchClick,
            resetClick,
        }
    },
} )
</script>
<style scoped lang="scss">
    #oplog {
        .box-f{
            :deep(.el-form-item__label){
                padding: 0;
            }
        }
        :deep(.el-card__body) {
            height: 100%;
        }
        ul {

            list-style: none;

            li {
                cursor: pointer;

                &:hover {
                    color: red;
                }
            }
        }
        .icon-e{
            :deep(.el-icon){
                margin-right: 0px!important;
            }
        }
    }
</style>